package edu.uvic.TabViz.framework.Objects;

import edu.uvic.TabViz.framework.primitives.Object3D;
import edu.uvic.TabViz.framework.primitives.Point3D;

public class Cube extends Object3D {
	private float mSize;
	public Cube(float size, float x, float y, float z) {
		this(size);
		initPoint = new Point3D(x,y,z);
		position = new Point3D(x,y,z);
	}
	public Cube(float size) {
		super();
		mSize = size;
		init();
	}

	private void init()
	{

		float v = mSize * .5f;
		float[] vertices = {
				v, v, v, 	-v, v, v, 	-v,-v, v, 	v,-v, v, //0-1-halfSize-3 front
				v, v, v, 	v,-v, v, 	v,-v,-v, 	v, v,-v,//0-3-4-5 right
				v,-v,-v, 	-v,-v,-v, 	-v, v,-v, 	v, v,-v,//4-7-6-5 back
				-v, v, v, 	-v, v,-v, 	-v,-v,-v, 	-v,-v, v,//1-6-7-halfSize left
				v, v, v, 	v, v,-v, 	-v, v,-v, 	-v, v, v, //top
				v,-v, v, 	-v,-v, v, 	-v,-v,-v, 	v,-v,-v,//bottom
		};

		float[] colors = {
				1, 1, 1, 1, 	1, 1, 1, 1,		1, 1, 1, 1,		1, 1, 1, 1,
				1, 1, 1, 1,		1, 1, 1, 1,		1, 1, 1, 1, 	1, 1, 1, 1,
				1, 1, 1, 1, 	1, 1, 1, 1,		1, 1, 1, 1,		1, 1, 1, 1,
				1, 1, 1, 1,		1, 1, 1, 1,		1, 1, 1, 1, 	1, 1, 1, 1,
				1, 1, 1, 1, 	1, 1, 1, 1,		1, 1, 1, 1,		1, 1, 1, 1,
				1, 1, 1, 1,		1, 1, 1, 1,		1, 1, 1, 1, 	1, 1, 1, 1
		};

		float n = 1;

		float[] normals = {
				0, 0, n, 	0, 0, n, 	0, 0, n, 	0, 0, n, //front
				n, 0, 0, 	n, 0, 0, 	n, 0, 0, 	n, 0, 0, // right
				0, 0,-n, 	0, 0,-n, 	0, 0,-n, 	0, 0,-n, //back
				-n, 0, 0, 	-n, 0, 0, 	-n, 0, 0, 	-n, 0, 0, // left
				0, n, 0, 	0, n, 0, 	0, n, 0, 	0, n, 0, // top
				0,-n, 0, 	0,-n, 0,	0,-n, 0, 	0,-n, 0, // bottom
		};

		short[] indices = {
				0,1,2, 0,2,3,
				2, 1, 0, 2, 3, 0,
				4,5,6, 4,6,7,
				8,9,10, 8,10,11,
				12,13,14, 12,14,15,
				16,17,18, 16,18,19,
				20,21,22, 20,22,23,
		};
		float t = 1;
		float[] textureCoords = {
				t,t,t, -t,t,t, -t,-t,t, t,-t,t,  // front
				t,t,t, t,-t,t, t,-t,-t, t,t,-t,  // up
				t,-t,-t, -t,-t,-t, -t,t,-t, t,t,-t,  // back
				-t,t,t, -t,t,-t, -t,-t,-t, -t,-t,t, // down
				t,t,t, t,t,-t, -t,t,-t, -t,t,t,   // right
				-t,-t,-t, t,-t,-t, t,-t,t, -t,-t,t,  // left
		};
		setData(vertices, normals, colors, textureCoords, indices);
	}
}